package br.com.sgdc.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import br.com.sgdc.view.action.ActionBuscaTextFieldWindowsBuscarArquivo;
import br.com.sgdc.view.util.Imagens;


public class WindowBuscarArquivo {
	public JDialog window = new JDialog();
	
	public JLabel buscaLabel = new JLabel("Nome do Arquivo: ");
	public JTextField buscaTextField = new JTextField(30);
	
	public ModeloTabelaWindowsBuscarArquivo modelo = new ModeloTabelaWindowsBuscarArquivo();
	
	public ModeloTabelaWindowsBuscarArquivo getModelo() {
		return modelo;
	}

	public WindowBuscarArquivo() {
		window.setTitle(".:: SGDC - Buscar Arquivos ::.");
		window.setSize(600, 350);
		window.setLocationRelativeTo(null);
		window.setIconImage(new ImageIcon(getClass().getResource(Imagens.cloud)).getImage());
	}
	
	public void initComponentesJanela() {
		this.initComponentes();

		window.setLayout(new BorderLayout());
		window.add(BorderLayout.NORTH,constructPrincipalPanel());
		window.add(BorderLayout.CENTER,constructTblArquivo());
		window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		window.setVisible(true);
	}
	
	private void initComponentes() {
		this.contructAction();
	}
	
	private Component constructPrincipalPanel() {
		JPanel panelGridOne = new JPanel();
		panelGridOne.setLayout(new GridLayout(1,1));
		panelGridOne.add(buscaTextField);
		
		
		JPanel panelGridTwo = new JPanel();
		panelGridTwo.setLayout(new GridLayout(1,1));
		panelGridTwo.add(buscaLabel);
		
		
		JPanel panelCenter = new JPanel();
		panelCenter.setLayout(new FlowLayout(FlowLayout.CENTER));
		panelCenter.add(panelGridTwo);
		panelCenter.add(panelGridOne);
		
		return panelCenter;
	}
	
	private JScrollPane constructTblArquivo() {
		JTable tabela = new JTable(modelo);
		tabela.setPreferredScrollableViewportSize(new Dimension(300,150));

		JScrollPane scrollPane = new JScrollPane(tabela);
		scrollPane.setBackground(Color.DARK_GRAY);
		scrollPane.setBorder(BorderFactory.createRaisedBevelBorder());

		return scrollPane;
	}
	
	private void contructAction() {
		buscaTextField.addKeyListener(new ActionBuscaTextFieldWindowsBuscarArquivo(this));

	}
}
